package com.cn.qtms.base.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @Name:BaseEntity
 * @Description: 实体类基类 封装一些公用字段
 * @Author: Neil
 * @Date: 2019-08-21 11:40
 **/
@Getter
@Setter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
public class BaseEntity implements Serializable {

    public static final String ID="id";
    public static final String IS_DELETE="isDelete";
    public static final String CREATOR="creator";
    public static final String CREATE_DATE="createDate";
    public static final String  UPDATER="updater";
    public static final String UPDATE_DATE="updateDate";
    @Id
    @Column(name="id", columnDefinition = "bigint(20) COMMENT 'id'")
    @JsonSerialize(using = ToStringSerializer.class)
    private  Long id;

    @JsonIgnore
    @Column(name = "is_delete", columnDefinition = "bit(1) default 0 COMMENT '是否已删除'")
    private Boolean isDelete = false;

    @JsonIgnore
    @Column(name="creator",columnDefinition="varchar(50) COMMENT '创建人'")
    @CreatedBy
    private String creator;

    @JsonIgnore
    @Column(name="create_date",columnDefinition="datetime COMMENT '创建时间'")
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @CreatedDate
    private Date createDate;

    @JsonIgnore
    @Column(name="updater",columnDefinition="varchar(50) COMMENT '修改人'")
    @LastModifiedBy
    private String updater;

    @JsonIgnore
    @Column(name="update_date",columnDefinition="datetime COMMENT '修改时间'")
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @LastModifiedDate
    private Date updateDate;

}
